package com.huifer.wgx.controller;

import com.huifer.wgx.model.DetectionLineEntity;
import com.huifer.wgx.model.DetectionPointEntity;
import com.huifer.wgx.pojo.CommonResult;
import com.huifer.wgx.service.DetectionLineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Title : DetectionLineController </p>
 * <p>Description : </p>
 *
 * @author huifer
 * @date 2019-03-21
 */
@RestController
@RequestMapping("detection_line")
@Api(tags = "DetectionLineController", description = "线段数据校验结果管理")
public class DetectionLineController {

    @Autowired
    private DetectionLineService detectionLineService;

    private CommonResult commonResult = new CommonResult();


    @ApiOperation("保存校验结果")
    @PostMapping("/save")
    public ResponseEntity saveDetectionList(
            @RequestParam("verify_id") Long verifyId,
            @RequestParam("work_id") Long workId,
            @RequestParam("personnel_id") Long personnelId) {
        try {
            List<DetectionLineEntity> list = detectionLineService
                    .createList(verifyId, workId, personnelId);
            return ResponseEntity
                    .ok(commonResult.success(detectionLineService.saveDetectionList(list)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }



    @ApiOperation("根据校验id查询线段数据校验结果")
    @GetMapping("/find_by_verify_id")
    public ResponseEntity findByPersonnelId(
            @RequestParam("personnel_id") Long personnelId,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(
                            detectionLineService
                                    .findByPersonnelId(personnelId, pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("根据校验人员名称查询线段数据校验结果")
    @GetMapping("/find_by_personnel_name")
    public ResponseEntity findByPersonnelName(
            @RequestParam("personnel_name") String personnelName,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(
                            detectionLineService
                                    .findByPersonnelName(personnelName, pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("根据校验id查询线段数据校验结果")
    @GetMapping("/findByVerifyId")
    public ResponseEntity findByVerifyId(
            @RequestParam("verify_id") Long verifyId,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(
                            detectionLineService.findByVerifyId(verifyId, pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("根据校验内容查询线段数据校验结果")
    @GetMapping("/find_by_verify_name")
    public ResponseEntity findByVerifyName(
            @RequestParam("verify_name") String verifyName,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(
                            detectionLineService.findByVerifyName(verifyName, pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("查询所有线段数据校验结果")
    @GetMapping("/find_all")
    public ResponseEntity findAllDl(
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(detectionLineService.findAll(pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }




}
